Page({
  data: {
    // 基本信息
    name: '',
    gender: '',
    nationality: '',
    address: '',
    idType: '',
    idcard: '',
    maritalStatus: '',
    mobile: '',
    talentType: '',
    talentDate: '',
    education: '',
    degree: '',
    school: '',
    age: '',
    diplomaNumber: '',
    title: '',
    email: '',
    
    // 配偶信息
    spouseName: '',
    spouseNationality: '',
    spouseIdType: '',
    spouseIdCard: '',
    spouseWorkplace: '',
    spouseTitle: '',
    
    // 选择器相关
    showGenderPicker: false,
    showIdTypePicker: false,
    showMaritalStatusPicker: false,
    showTalentTypePicker: false,
    showEducationPicker: false,
    showDegreePicker: false,
    showSpouseIdTypePicker: false,
    
    // 选项数据
    genderActions: [
      { name: '男' },
      { name: '女' }
    ],
    idTypeActions: [
      { name: '身份证' },
      { name: '护照' },
      { name: '港澳通行证' },
      { name: '台湾通行证' }
    ],
    maritalStatusActions: [
      { name: '未婚' },
      { name: '已婚' },
      { name: '离异' },
      { name: '丧偶' }
    ],
    talentTypeActions: [
      { name: '国家级人才' },
      { name: '省级人才' },
      { name: '市级人才' },
      { name: '区级人才' }
    ],
    educationActions: [
      { name: '专科' },
      { name: '本科' },
      { name: '硕士研究生' },
      { name: '博士研究生' }
    ],
    degreeActions: [
      { name: '学士' },
      { name: '硕士' },
      { name: '博士' }
    ],
  },
  
  onInput(e) {
    const key = e.currentTarget.dataset.key;
    this.setData({ [key]: e.detail });
  },
  
  // 选择性别
  onSelectGender() {
    this.setData({ showGenderPicker: true });
  },
  
  onConfirmGender(event) {
    const { detail } = event;
    this.setData({
      gender: detail.name,
      showGenderPicker: false
    });
  },
  
  // 选择证件类型
  onSelectIdType() {
    this.setData({ showIdTypePicker: true });
  },
  
  onConfirmIdType(event) {
    const { detail } = event;
    this.setData({
      idType: detail.name,
      showIdTypePicker: false
    });
  },
  
  // 选择配偶证件类型
  onSelectSpouseIdType() {
    this.setData({ showSpouseIdTypePicker: true });
  },
  
  onConfirmSpouseIdType(event) {
    const { detail } = event;
    this.setData({
      spouseIdType: detail.name,
      showSpouseIdTypePicker: false
    });
  },
  
  // 选择婚姻状态
  onSelectMaritalStatus() {
    this.setData({ showMaritalStatusPicker: true });
  },
  
  onConfirmMaritalStatus(event) {
    const { detail } = event;
    this.setData({
      maritalStatus: detail.name,
      showMaritalStatusPicker: false
    });
  },
  
  // 选择人才类型
  onSelectTalentType() {
    this.setData({ showTalentTypePicker: true });
  },
  
  onConfirmTalentType(event) {
    const { detail } = event;
    this.setData({
      talentType: detail.name,
      showTalentTypePicker: false
    });
  },
  
  // 选择人才资格获取时间
  onSelectTalentDate() {
    wx.navigateTo({
      url: '/pages/common/date-picker?field=talentDate'
    });
  },
  
  // 选择学历
  onSelectEducation() {
    this.setData({ showEducationPicker: true });
  },
  
  onConfirmEducation(event) {
    const { detail } = event;
    this.setData({
      education: detail.name,
      showEducationPicker: false
    });
  },
  
  // 选择学位
  onSelectDegree() {
    this.setData({ showDegreePicker: true });
  },
  
  onConfirmDegree(event) {
    const { detail } = event;
    this.setData({
      degree: detail.name,
      showDegreePicker: false
    });
  },
  
  // 关闭选择器
  onClosePicker() {
    this.setData({
      showGenderPicker: false,
      showIdTypePicker: false,
      showMaritalStatusPicker: false,
      showTalentTypePicker: false,
      showEducationPicker: false,
      showDegreePicker: false,
      showSpouseIdTypePicker: false
    });
  },
  
  go(e) {
    const url = e.currentTarget.dataset.url;
    wx.navigateTo({
      url
    });
  },
  
  onLoad(options) {
    // 接收日期选择页面返回的数据
    // const eventChannel = this.getOpenerEventChannel();
    // if (eventChannel) {
    //   eventChannel.on('selectedDate', (data) => {
    //     this.setData({
    //       talentDate: data.date
    //     });
    //   });
    // }
  }
})